<?php
/**
 * 公告管理model
 * @author lxn
 */
class Refund_model extends MY_Model
{
	private $table = 'refund';
	public function __construct()
	{
		parent::__construct($this->table);
	}
	
	
	/**
	 * 获取约见订单列表(后台用)
	 */
	public function getList_yuYue_admin( $page =0, $limit = 20,$search='',$where = array())
	{
	    $select = 'orderlist.*,course.courseId,course.title,user.userId,expert.expertId,user.nickName,user.realName,expert.name as expertName,refund.reason,refund.desc';
	    $this->db->select($select);
	    if($search){
	        $this->db->group_start();
	        $this->db->like('user.nickName',$search);
	        $this->db->or_like('user.realName',$search);
	        $this->db->group_end();
	    }
	    $this->formatWhere($where);
	    $this->db->where('orderlist.typeFLag',1);
	    $this->db->join('user','user.userId=orderlist.userId','left');
	    $this->db->join('course','course.courseId=orderlist.listId','left')->join('expert','expert.expertId=course.expertId','left');
	    $this->db->order_by('status','asc')->order_by('orderlist.createTime', 'desc')->limit($limit, $page*$limit);
	    return $this->db->get($this->table)->result_array();
	}
	//获取预约订单总量
	public function getCount_yuYue($search='',$where=array()){
	    if($search){
	        $this->db->group_start();
	        $this->db->like('user.nickName',$search);
	        $this->db->or_like('user.realName',$search);
	        $this->db->group_end();
	    }
	    $this->formatWhere($where);
	    $this->db->where('typeFlag',1);
	    $this->db->join('user','user.userId=orderlist.userId');
	    return $this->db->get($this->table)->num_rows();
	}
	
	/**
	 * 获取竞拍订单列表(后台用)
	 */
	public function getList_auction_admin($page =0, $limit = 20,$search='',$where = array())
	{
	    $select = 'orderlist.*,auction.auctionId,user.userId,expert.expertId,user.nickName,user.realName,expert.name as expertName,refund.reason,refund.desc';
	    $this->db->select($select);
	    if($search){
	        $this->db->group_start();
	        $this->db->like('user.nickName',$search);
	        $this->db->or_like('user.realName',$search);
	        $this->db->group_end();
	    }
	    $this->formatWhere($where);
	    
	    $this->db->where('typeFLag',2);
	    $this->db->join('user','user.userId=orderlist.userId','left');
	    $this->db->join('auction','auction.auctionId=orderlist.listId','left')->join('expert','expert.expertId=auction.expertId','left');
	    $this->db->order_by('status','asc')->order_by('orderlist.createTime', 'desc')->limit($limit, $page*$limit);
	    return $this->db->get($this->table)->result_array();
	}
	//获取预约订单总量
	public function getCount_auction($search='',$where=array()){
	    if($search){
	        $this->db->group_start();
	        $this->db->like('user.nickName',$search);
	        $this->db->or_like('user.realName',$search);
	        $this->db->group_end();
	    }
	    $this->formatWhere($where);
	    $this->db->where('typeFlag',2);
	    $this->db->join('user','user.userId=orderlist.userId');
	    return $this->db->get($this->table)->num_rows();
	}
	public function formatWhere($where){
	    if($where){
	        if(isset($where['status'])&&empty($where['status'])){
	            unset($where['status']);
	           
	        }
	        if(isset($where['orderFlag'])&&empty($where['orderFlag'])){
	            unset($where['orderFlag']);
	        }
	        if($where){
	            
	            $this->db->where($where);
	        }
	    }
	}
	
	//插入数据
	public function insert($data){
	    $data['createTime']=time();
	    $this->db->insert($this->table,$data);
	    return $this->db->insert_id();
	}
	//自定义条件数组更多 新数据
	public function updateWhere($where,$data){
	    $this->db->where($where);
	    $this->db->update($this->table,$data);
	    return $this->db->affected_rows();
	}
	//获取退款单及订单信息
	public function getRefundInfo($refundId){
	    $this->db->select('refund.*,orderlist.price,orderlist.trade_no,');
	    $this->db->where('refundId',$refundId);
	    $this->db->join('orderlist','orderlist.orderId=refund.orderId');
	    return $this->db->get($this->table)->row_array();
	}
}
/* End of file Linkadmin_model.php */